"""OSD overlay utilities (moved from io/)."""
import cv2  # type: ignore


def put_text(img, text: str, org=(10, 24), color=(0, 255, 0), scale=0.7):
    cv2.putText(img, text, org, cv2.FONT_HERSHEY_SIMPLEX, scale, color, 2, cv2.LINE_AA)
    return img


def draw_bbox(img, bbox, color=(0, 255, 0), label: str | None = None):
    x1, y1, x2, y2 = bbox
    cv2.rectangle(img, (x1, y1), (x2, y2), color, 2)
    if label:
        cv2.putText(img, label, (x1, max(0, y1 - 4)), cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2, cv2.LINE_AA)
    return img


def draw_polygon(img, pts, color=(0, 255, 255)):
    import numpy as np
    pts = np.array(pts, dtype=np.int32)
    cv2.polylines(img, [pts], isClosed=True, color=color, thickness=2)
    return img

